﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using QWeiBo.ViewModel;
using TencentWeiboSDK.Services;
using TencentWeiboSDK.Services.Util;
using System.Threading;
using TencentWeiboSDK.Model;

namespace QWeiBoN.ViewModule
{
    /// <summary>
    /// 点评发布类
    /// </summary>
    public class TextCommentModel : BaseViewModel
    {
        /// <summary>
        /// 声明业务处理
        /// </summary>
        TService service = new TService();

        /// <summary>
        /// 进行微博评论
        /// </summary>
        /// <param name="content"></param>
        /// <param name="textId"></param>
        /// <param name="action"></param>
        public void textComment(string content, string textId, Action<Callback<Result>> action)
        {
            // 增加用户体验，进行异步操作
            new Thread(() =>
            {
                Action<Callback<Result>> action1 = new Action<Callback<Result>>((callBack) =>
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        if (null == callBack.InnerException)
                        {
                            MessageBox.Show("微博评论成功");
                        }
                        else
                        {
                            MessageBox.Show(callBack.InnerException.Message);
                        }
                    });

                    if (null != action)
                    {
                        action(callBack);
                    }
                });

                service.Comment(new ServiceArgument() { Content = content, Reid = textId }, action1);

            }).Start();
        }
    }
}
